
let Benchmark = require('benchmark');
let suite = new Benchmark.Suite;


suite.add('test1',function () {
    test3();
}).add('test2',function () {
    test4();
}).on('cycle',function (event) {
   console.log(String(event.target));
}).run({async:true});


function test1(){
    const arr1 = [{uuid: 1, value: 123, key: 12345}, {uuid: 2, value: 111, key: 98776}, {uuid: 3, value: 222, key: 222}];
    const arr2 = [{uuid: 2, value: 333, key: 777}, {uuid: 1, value: 444, key: 555}];

    arr2.forEach(item=>{
        let uuid = item.uuid;
        let targetItem = arr1.find((item2)=>{
            return item2.uuid === uuid;
        });
        if(targetItem){
            for(let k in item){
                targetItem[k] = item[k];
            }
        }
    });
}
function test2(){
    const arr1 = [{uuid: 1, value: 123, key: 12345}, {uuid: 2, value: 111, key: 98776}, {uuid: 3, value: 222, key: 222}];
    const arr2 = [{uuid: 2, value: 333, key: 777}, {uuid: 1, value: 444, key: 555}];

    const obj = {};
    [...arr1,...arr2].forEach(item=>obj[item.uuid] = item);
}

function test3() {
    let a = 1111;
    let b = 2222;
    [a,b] = [b,a];
    // console.log(a,b);
}

function test4() {
    let a = 1111;
    let b = 2222;
    a = a ^ b;
    b = a ^ b;
    a = a ^ b;
    // console.log(a,b);
}
// test4();
